from __future__ import annotations

from dataclasses import dataclass
from math import cos, sin
from typing import List


@dataclass
class Slice:
    width_m: float
    height_m: float
    unit_weight_kN_m3: float
    cohesion_kPa: float
    friction_deg: float
    base_inclination_deg: float


@dataclass
class SlopeStabilityResult:
    factor_of_safety: float
    note: str


def fellenius_circular_slope(slices: List[Slice], radius_m: float) -> SlopeStabilityResult:
    """瑞典条分法（Fellenius）圆弧滑动简化 Fs。

    Fs = Σ (c'·b + (W - u·b)·tanφ') / Σ (W·sinα)
    这里忽略孔压 u，近似计算。
    """

    import math
    numerator = 0.0
    denominator = 0.0
    for s in slices:
        b = s.width_m
        W = s.width_m * s.height_m * s.unit_weight_kN_m3
        alpha = math.radians(s.base_inclination_deg)
        phi = math.radians(s.friction_deg)
        numerator += s.cohesion_kPa / 1000.0 * b + W * math.tan(phi) * math.cos(alpha)
        denominator += W * math.sin(alpha)
    Fs = numerator / max(1e-6, denominator)
    return SlopeStabilityResult(factor_of_safety=Fs, note="Fellenius圆弧滑动-忽略孔压")


